<?php

class Login extends MY_Controller {

	function Login()
	{
		parent::MY_Controller();
	}

    //admin login page
	function index()
	{
        $this->lang->load('title');
        $title = $this->lang->line('title_admin_login');
        $this->lang->load('login');
        $this->template->assign('login_form',$this->lang);
		$this->template->assign('title',$title);
		$this->template->view('login');
	}

    //process the admin login action
    function user()
    {
        $this->load->model('loginModel');
        $admin_user = $this->input->post('admin_user');
        $admin_pass = $this->input->post('admin_pass');
        $admin_pass = sha1($admin_pass);
        $flag = $this->loginModel->get_valid_admin($admin_user,$admin_pass);
        $this->load->helper('js');
        if($flag === FALSE) {
            $error = 1;
            js_back();
        } else {
            $this->set_admin_session($admin_user);
            js_go(base_url().'admin/');
        }
    }
    
    /**
     * 管理员退出
     * @return unknown_type
     */
    function logout(){
    	self::unset_session_value('username');
    	echo '<script>window.top.location.href="/login/";</script>';
    	//self::redirect('注销成功',base_url().'admin/');
    }

    //set admin session info
    function set_admin_session($username)
    {
        $this->load->library('session');
        $this->session->set_userdata('username', $username);
        return;
    }

    //get admin session
    function get_admin_session()
    {
        $this->load->library('session');
        return $this->session->userdata('username');
    }

}

/* End of file login.php */
/* Location: ./system/application/controllers/login.php */